import requests

url = 'https://fanyi.so.com/index/search?eng=1&validate=&ignore_trans=0&query=hello%0A'

head = {
    "Accept": "application/json, text/plain, */*",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Content-Length": "0",
    "Cookie": "QiHooGUID=82EE8F3700A54721C87221761C63ED71.1691378976054; Q_UDID=af16e2da-e0f6-64f5-b5b1-feda5f429310; __guid=144965027.1258885502628468000.1691378975653.8003; count=2",
    "Origin": "https://fanyi.so.com",
    "Pro": "fanyi",
    "Referer": "https://fanyi.so.com/",
    "Sec-Ch-Ua": '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
    "Sec-Ch-Ua-Mobile": "?0",
    "Sec-Ch-Ua-Platform": '"Windows"',
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-origin",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
}

shuru = input("请输入你要翻译的内容:")
eng=1
question = len(shuru[0].encode(encoding='utf-8'))
print(question)
if question == 1:
    eng=1
elif question==3:
    eng = 0
zaihe = {
    "eng": eng,
    "ignore_trans": 0,
    "query": shuru
}
res = requests.post(url, headers=head, data=zaihe)
data = res.json()['data']['fanyi']
print("这是翻译结果:", data)

